import { reactive } from "vue";
import type { FormRules } from "element-plus";

/** 自定义表单规则校验 */

export const formRules = reactive(<FormRules>{
  taskName: [{ required: true, message: "任务名称为必填项", trigger: "blur" }],
  deadline: [
    {
      validator: (rule, value, callback) => {
        if (value === "") {
          callback();
        } else {
          const now = new Date();
          const deadline = new Date(value);
          if (deadline < now) {
            callback(new Error("截止时间不能早于当前时间"));
          } else {
            callback();
          }
        }
      },
      trigger: "blur"
    }
  ],
  assigneeId: [{ required: true, message: "请选择负责人", trigger: "change" }],
  status: [{ required: true, message: "请选择任务状态", trigger: "change" }],
  priority: [{ required: true, message: "请选择优先级", trigger: "change" }]
});
